package com.lkx.farmershop.controller;

import com.lkx.farmershop.common.api.ApiResult;
import com.lkx.farmershop.model.vo.CollectVo;
import com.lkx.farmershop.service.CollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/collect")
public class CollectController {

    @Autowired
    private CollectService collectService;

    /**
     * 收藏/取消收藏组团
     * @param tuanId
     * @param userId
     * @return
     */
    @Transactional
    @PostMapping("/collectGroup")
    public ApiResult<String> collectGroup(@RequestParam("tuanId") Long tuanId, @RequestParam("userId") Long userId) {
        return collectService.collectGroup(tuanId, userId);
    }

    /**
     * 判断用户是否已经收藏该团
     * @param tuanId
     * @param userId
     * @return
     */
    @GetMapping("/hasCollected")
    public ApiResult<Boolean> hasCollected(@RequestParam("tuanId") Long tuanId, @RequestParam("userId") Long userId) {
        return collectService.hasCollected(tuanId, userId);
    }

    @GetMapping("/getCollectList")
    public ApiResult<List<CollectVo>> getCollectList(@RequestParam("userId") Long userId) {
        return collectService.getCollectList(userId);
    }
}
